<?php
header("Content-type: text/html; charset=utf-8");

define("ACCESS_TOKEN", 'bsda960OqfvOj7NZceNGaO-JWEXF_tqni-w3tEgKFHDfkdyWLpLkIzeYM6FWrsEaZ4Lm6KTwLbzbz9gIY-_hZmHWBe3F6UrHflOJn_dHGukPYcXaI_5G4deI-d5hKEVOgNMH6-THT7k9TimW4vyTEA');

$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN;

 
function vpost($url,$data){ // 模拟提交数据函数
    $curl = curl_init(); // 启动一个CURL会话
    curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); // 模拟用户使用的浏览器
    // curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
    // curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包x
    curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
    $tmpInfo = curl_exec($curl); // 执行操作
    if (curl_errno($curl)) {
       echo 'Errno'.curl_error($curl);//捕抓异常
    }
    curl_close($curl); // 关闭CURL会话
    return $tmpInfo; // 返回数据
}

//创建菜单
function createMenu($data){
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $tmpInfo = curl_exec($ch);
 if (curl_errno($ch)) {
  return curl_error($ch);
 }
 curl_close($ch);
 return $tmpInfo;
}

$data = ' {
     "button":[
     
      {
           "name":"云创理财",
           "sub_button":[
            {
               "type":"view",
               "name":"我要理财",
			   "url":"http://www.huayinziben.com/mobile/borrow/index.html"
            },
			{
               "type":"view",
               "name":"我的账号",
			   "url":"http://www.huayinziben.com/mobile/ucenter/index.html"
            },
			{
               "type":"view",
               "name":"交易记录",
			   "url":"http://www.huayinziben.com/mobile/account/account_list.html"
            }]
       },
	   {
           "name":"帮助中心",
           "sub_button":[
            {
               "type":"click",
               "name":"本金保障",
               "key":"baozheng"
            },
            {
               "type":"click",
               "name":"发展历程",
               "key":"development"
            }]
       },
	   {
           "name":"公司介绍",
           "sub_button":[
            {
               "type":"click",
               "name":"联系我们",
               "key":"about"
            },
            {
               "type":"click",
               "name":"平台介绍",
               "key":"introduction"
            },
			{
               "type":"click",
               "name":"媒体报道",
               "key":"activity"
            }
			]
       }	   
	   ]
 }';

$result = vpost($url,$data);
var_dump($result);
//echo createMenu($data);//创建菜单
?>